﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_MobilizationNoticeController : BaseApiController
    {
        #region DI

        public PB_MobilizationNoticeController(IPB_MobilizationNoticeBusiness pB_MobilizationNoticeBus)
        {
            _pB_MobilizationNoticeBus = pB_MobilizationNoticeBus;
        }

        IPB_MobilizationNoticeBusiness _pB_MobilizationNoticeBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_MobilizationNotice>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_MobilizationNoticeBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<PB_MobilizationNoticeDto> GetTheData(IdInputDTO input)
        {
            return await _pB_MobilizationNoticeBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_MobilizationNotice data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_MobilizationNoticeBus.AddDataAsync(data);
            }
            else
            {
                await _pB_MobilizationNoticeBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_MobilizationNoticeBus.DeleteDataAsync(ids);
        }
        /// <summary>
        /// 保存编辑进场通知单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SavaDataList(PB_MobilizationNoticeSubDTO data) {

            if (data.MaiData.Id.IsNullOrEmpty())
            {
                InitEntity(data.MaiData);
                data.MaiData.AuditStatus = 0;
                await _pB_MobilizationNoticeBus.AddDataListInfo(data);
            }
            else {
                await _pB_MobilizationNoticeBus.UpdateDataListInfo(data);
            }
        }

        /// <summary>
        /// 审核进场通知单
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task AuditStatus(string Id) {
            await _pB_MobilizationNoticeBus.ToExamineRepairOrderApply(Id);
        }
        /// <summary>
        /// 打印进场通知单
        /// </summary>
        /// <param name="Id">进厂通知单号</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_MobilizationNoticePrint> MobilizationNoticePrint(string Id) {
            var ListData =await _pB_MobilizationNoticeBus.MobilizationNoticePrint(Id);
            return ListData;
        }
        #endregion
    }
}